package io.dcloud.uniplugin.dialogfragment;

import android.app.Activity;
import android.view.View;

import androidx.annotation.LayoutRes;

import io.dcloud.uniplugin.R;

/*
 * 操作人 :  yzhg
 * 时  间 :  2019/9/21 0021
 * 描  述 :
 */public class CommonBasicDialog extends BaseDialogFragment {

    private ViewConvertListener convertListener;

    private ViewHolder holder;
    private Activity mActivity;
    private String mLanguage;

    public static CommonBasicDialog newInstance() {
        return new CommonBasicDialog();
    }

    /**
     * 操作人 : yzhg
     * 描  述 : 设置Dialog布局
     */
    public CommonBasicDialog setLayoutId(@LayoutRes int layoutId) {
        this.mLayoutResId = layoutId;
        return this;
    }

    public void setLanguage(String language) {
        this.mLanguage = language;
    }

    public void setActivity(Activity activity) {
        this.mActivity = activity;
    }

    @Override
    public int setUpLayoutId() {
        return mLayoutResId;
    }

    @Override
    public void convertView(ViewHolder holder, BaseDialogFragment dialog) {
        this.holder = holder;
//        if (convertListener != null) {
//            convertListener.convertView(holder, dialog);
//        }

        if (mLanguage != null && mLanguage.equals("zh")) {
            holder.setText(R.id.tv_content, "准备扫描，请将卡片贴近手机");
            holder.setText(R.id.tvDialogTitle, "已准备好扫描");
            holder.setText(R.id.tvCancel, "取消");
        } else {
            holder.setText(R.id.tv_content, "Ready to scan, hold the card close to your phone");
            holder.setText(R.id.tvDialogTitle, "Ready to scan");
            holder.setText(R.id.tvCancel, "Cancel");
        }

        holder.setOnClickListener(R.id.iv_cancle, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismissDialog();
                mActivity.finish();
            }
        });

        holder.setOnClickListener(R.id.ll_cancle, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismissDialog();
                mActivity.finish();
            }
        });
    }

    public void setContent(String content) {
        holder.setText(R.id.tv_content, content);
    }

    public void setGif(int drawable) {
        holder.setImgGif(R.id.iv_img, drawable);
    }

//    public CommonBasicDialog setConvertListener(ViewConvertListener convertListener) {
//        this.convertListener = convertListener;
//        return this;
//    }
}